<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        /* 低饱和度浅蓝色背景 */
        body {
            background: linear-gradient(-45deg, #e9e2f3, #d4c9e8, #d1c9ec,
            #e4e2f5, #e6f2e9,
            #e1eaf5, #c9d9ec, #f9e6ea, #f0ccd8);
            background-size: 400% 400%;
            animation: gradient 8s ease infinite; /* 8秒循环一次 */
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0;
        }
        /* 背景渐变动画 */
        @keyframes gradient {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        /* 登录卡片（毛玻璃+hover上浮） */
        .login-card {
            width: 100%;
            max-width: 400px;
            padding: 2.5rem;
            background-color: rgba(255, 255, 255, 0.9);
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            backdrop-filter: blur(5px);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .login-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.12);
        }

        /* 标题下划线动画 */
        .login-title {
            text-align: center;
            margin-bottom: 2rem;
            color: #333;
            font-weight: 700;
            font-size: 1.8rem;
            position: relative;
        }
        .login-title::after {
            content: '';
            width: 50px;
            height: 3px;
            background-color: #8ab4f8; /* 浅蓝下划线 */
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            animation: underline 1.5s ease infinite alternate;
        }
        @keyframes underline {
            from { width: 30px; }
            to { width: 70px; }
        }

        /* 输入框悬浮光效（底部渐变光条） */
        .form-group {
            position: relative;
            margin-bottom: 1.5rem;
        }
        .form-label {
            color: #666;
            font-size: 0.95rem;
        }
        .form-control {
            border: none;
            border-bottom: 2px solid #eee;
            border-radius: 0;
            padding: 0.75rem 0;
            background: transparent;
            transition: all 0.3s ease;
        }
        .form-control:focus {
            border-color: #8ab4f8;
            box-shadow: none;
            outline: none;
        }
        /* 底部光条动画 */
        .form-control:focus + .input-glow {
            width: 100%;
        }
        .input-glow {
            position: absolute;
            bottom: 0;
            left: 0;
            height: 2px;
            background: linear-gradient(90deg, #8ab4f8, #b5d8fe);
            width: 0;
            transition: width 0.5s ease;
        }

        /* 错误提示淡入 */
        .error-message {
            color: #dc3545;
            font-size: 0.9rem;
            margin-top: 0.5rem;
            text-align: center;
            animation: fadeIn 0.5s ease-in-out;
        }
        @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

        /* 登录按钮（加载状态+hover动效） */
        .btn-login {
            transition: all 0.3s ease;
            padding: 0.75rem;
            font-weight: 500;
            background-color: #8ab4f8;
            border: none;
            border-radius: 25px;
        }
        .btn-login:hover {
            background-color: #6ea8f5;
            transform: scale(1.02);
            box-shadow: 0 4px 15px rgba(142, 180, 248, 0.3);
        }
        /* 加载状态动画 */
        .btn-loading::after {
            content: '';
            position: absolute;
            width: 18px;
            height: 18px;
            border: 2px solid rgba(255, 255, 255, 0.8);
            border-top-color: transparent;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
        }
        @keyframes spin {
            to { transform: translateY(-50%) rotate(360deg); }
        }

        /* 注册链接样式优化 */
        .register-link {
            color: #6ea8f5;
            text-decoration: none;
            transition: color 0.3s ease;
        }
        .register-link:hover {
            color: #4a89dc;
            text-decoration: underline;
        }
    </style>
</head>

<body>
<div class="login-card">
    <h2 class="login-title">用户登录</h2>
    <!-- 1. 表单action改为/doLogin -->
    <form th:action="@{/doLogin}" method="post" id="loginForm">
        <!-- 用户名输入框（带光效） -->
        <div class="form-group">
            <label for="username" class="form-label">用户名</label>
            <input type="text" class="form-control" id="username" name="username"
                   placeholder="请输入用户名" required>
            <div class="input-glow"></div>
        </div>
        <!-- 密码输入框（带光效） -->
        <div class="form-group">
            <label for="password" class="form-label">密码</label>
            <input type="password" class="form-control" id="password" name="password"
                   placeholder="请输入密码" required>
            <div class="input-glow"></div>
        </div>
        <!-- 2. 错误提示改为errorMsg -->
        <div th:if="${errorMsg != null}" class="error-message" th:text="${errorMsg}">
            用户名或密码错误，新用户请先注册
        </div>
        <!-- 登录按钮（带加载状态） -->
        <button type="submit" class="btn w-100 btn-login" >登录</button>
        <!-- 3. 新增注册入口 -->
        <div class="text-center mt-3">
            <span class="text-muted">新用户？</span>
            <a href="/register" class="register-link">立即注册</a>
        </div>
    </form>
</div>

<!-- 按钮加载状态JS -->
<script>
    const loginForm = document.getElementById('loginForm');
    const loginBtn = loginForm.querySelector('button');

    loginForm.addEventListener('submit', () => {
        // 点击登录后，按钮进入加载状态
        loginBtn.classList.add('btn-loading');
        loginBtn.textContent = '登录中...';
        // 禁止重复提交
        loginBtn.disabled = true;
    });
</script>
</body>
</html>